<?
include_once("./_common.php");
header("Content-type: text/xml");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";

if (iconv("cp949", "cp949", $q) == $q)
    $q = iconv("cp949", "utf-8", $q);
    
echo "<items>\n";
if ($q) {
    $any = "";
    if ($like)
        $any = "%";

    $sql = " select a.search, a.cnt ";
    $sql .= " from ( ";
    $sql .= " select wr_10 as search, count(*) as cnt from g4_write_sellitem where 1 and wr_10 like '".$any.$q."%' group by wr_10 limit 10";
    $sql .= " union all ";
    $sql .= " select itembrand as search, count(*) as cnt from g4_write_sellitem where 1 and itembrand like '".$any.$q."%' group by itembrand limit 10";
    $sql .= " union all ";
    $sql .= " select itemname as search, count(*) as cnt from g4_write_sellitem where 1 and itemname like '".$any.$q."%' group by itemname limit 10";
    $sql .= " ) a order by a.cnt desc, a.search limit 10 ";
    
    echo $sql;
    
    $result = sql_query($sql);
    for($i=0;$row=sql_fetch_array($result);$i++) {
        if ($i>0)
            $javascript_object .= ",";
        $s = stripslashes(strip_tags($row[search]));
        $s = str_replace("[", "", $s);
        $s = str_replace("]", "", $s);
        $s = str_replace("\n", "", $s);
        $s = str_replace("\r", "", $s);
        $str = iconv("utf-8", "cp949", $s);
        $str = $s;
        echo "<item>$str</item>\n";
    }
}
echo "</items>";
?>